﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class editnv : System.Web.UI.Page
{
    SqlConnection conn;
    SqlCommand cmd;
    SqlDataReader dr;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["manv"] != null)
            {
                datasever data = new datasever();
                conn = data.getconnect();
                cmd = new SqlCommand("getnhanvien", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@manv", Request.QueryString["manv"].ToString()));
                dr = cmd.ExecuteReader();
                dr.Read();
                manv.Text = dr["manv"].ToString();
                txttennv.Text = dr["tennv"].ToString();
                txtsodt.Text = dr["sodt"].ToString();
                txtuseid.Text = dr["userid"].ToString();
                txtpass.Text = dr["pass"].ToString();
                conn.Close();
            }
        }
         
    }
    protected void bt1_Click(object sender, EventArgs e)
    {
        datasever data = new datasever();
        conn = data.getconnect();
        if (Request.QueryString["action"] != null)
        {
            cmd = new SqlCommand("insertnhanvien", conn);
        }
        else
        {
            cmd = new SqlCommand("updatenhanvien", conn);
        }
        int i = 0;
        if (ckgt.Checked == true)
            i = 1;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("manv",manv.Text));
        cmd.Parameters.Add(new SqlParameter("tennv", txttennv.Text));
        cmd.Parameters.Add(new SqlParameter("sodt", txtsodt.Text));
        cmd.Parameters.Add(new SqlParameter("userid", txtuseid.Text));
        cmd.Parameters.Add(new SqlParameter("pass", txtpass.Text));
        cmd.Parameters.Add(new SqlParameter("gioitinh",i));
        cmd.ExecuteNonQuery();
        Response.Redirect("Default.aspx");
        conn.Close();

    }
}